﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cwtrock.model;
using cwtrock.util;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

namespace cwtrock.dao.impl
{
    class SysDataDaoImpl : BasicDaoImpl
    {
        private GetConn getConn = new GetConn();

        public List<SysData> getSysDataByType(String type) {

            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" SELECT   item_code, item_name  ");
                strSql.Append("   FROM SYS_DATA WHERE  item_type=@type");


                SqlParameter[] parameters = { 
                new SqlParameter("@type",SqlDbType.VarChar,50)
                                        };

                 parameters[0].Value = type;
                

                    SqlCommand cmd = new SqlCommand(strSql.ToString(), getConn.GetCon());
                    cmd.Parameters.Add(parameters[0]);
                    cmd.ExecuteNonQuery();

                    SqlDataReader reader = cmd.ExecuteReader();
                    List<SysData> ls = new List<SysData>();
                    while (reader.Read())
                    {
                        SysData data = new SysData();
                        data.Itemcode = reader[0].ToString();
                        data.Itemname= reader[1].ToString();
                        ls.Add(data);
                    }

                    return ls;

            }
            catch (Exception e)
            {
                throw e;
                return null;
            }


        }

    }
}
